home *** CD-ROM | disk | FTP | other *** search
/ Just Call Me Internet / Just Call Me Internet.iso / prog / mint / netlib / include / net.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-27  |  4.5 KB  |  135 lines

  1. /*
  2.  *    Definitions for the socket layer.
  3.  *
  4.  *    09/27/93, kay roemer
  5.  */
  6.  
  7. #ifndef _NET_H
  8. #define _NET_H
  9.  
  10. #include "socket.h"
  11. #include "iov.h"
  12.  
  13. /* possible socket states */
  14. enum so_state {
  15.     SS_VIRGIN = 0,
  16.     SS_ISUNCONNECTED,
  17.     SS_ISCONNECTING,
  18.     SS_ISCONNECTED,
  19.     SS_ISDISCONNECTING,
  20.     SS_ISDISCONNECTED
  21. };
  22.  
  23. /* possible socket flags */
  24. #define SO_ACCEPTCON    0x0001        /* socket is accepting connections */
  25. #define SO_RCVATMARK    0x0002        /* in-band and oob data are in sync */
  26. #define SO_CANTRCVMORE    0x0004        /* shut down for receives */
  27. #define SO_CANTSNDMORE    0x0008        /* shut down for sends */
  28. #define SO_CLOSING    0x0010        /* socket is close()ing */
  29. #define SO_DROP        0x0020        /* drop connecting socket when accept()
  30.                        fails due to lacking file handles */
  31.  
  32. struct socket {
  33.     enum so_type    type;        /* socket type: SOCK_* */
  34.     enum so_state    state;        /* socket state: SS_* */
  35.     short        flags;        /* socket flags: SO_* */
  36.     struct socket    *conn;        /* peer socket */
  37.     struct socket    *iconn_q;    /* queue of imcomplete connections */
  38.     struct socket    *next;        /* next connecting socket in list */
  39.     struct dom_ops    *ops;        /* domain specific operations */
  40.     void        *data;        /* domain specific data */
  41.     short        error;        /* async. error */
  42.     short        pgrp;        /* process group to send sinals to */
  43.     long        rsel;        /* process selecting for reading */
  44.     long        wsel;        /* process selecting for writing */
  45.     long        xsel;        /* process selecting for exec. cond. */
  46.     short        date;        /* date stamp */
  47.     short        time;        /* time stamp */
  48.     short        lockpid;    /* pid of locking process */
  49. };
  50.  
  51. /* domain, as the socket level sees it */
  52. struct dom_ops {
  53.     short        domain;
  54.     struct dom_ops    *next;
  55.     long    (*attach)    (struct socket *s, short proto);
  56.     long    (*dup)        (struct socket *news, struct socket *olds);
  57.     long    (*abort)    (struct socket *s, enum so_state ostate);
  58.     long    (*detach)    (struct socket *s);
  59.     long    (*bind)        (struct socket *s, struct sockaddr *addr,
  60.                 short addrlen);
  61.  
  62.     long    (*connect)    (struct socket *s, struct sockaddr *addr,
  63.                 short addrlen, short flags);
  64.  
  65.     long    (*socketpair)    (struct socket *s1, struct socket *s2);
  66.     long    (*accept)    (struct socket *s, struct socket *new,
  67.                  short flags);
  68.  
  69.     long    (*getname)    (struct socket *s, struct sockaddr *addr,
  70.                  short *addrlen, short peer);
  71. #define PEER_ADDR    0
  72. #define SOCK_ADDR    1
  73.     long    (*select)    (struct socket *s, short sel_type, long proc);
  74.     long    (*ioctl)    (struct socket *s, short cmd, void *arg);
  75.     long    (*listen)    (struct socket *s, short backlog);
  76.     long    (*send)        (struct socket *s, struct iovec *iov,
  77.                 short niov, short block, short flags,
  78.                 struct sockaddr *addr, short addrlen);
  79.  
  80.     long    (*recv)        (struct socket *s, struct iovec *iov,
  81.                 short niov, short block, short flags,
  82.                 struct sockaddr *addr, short *addrlen);
  83.  
  84.     long    (*shutdown)    (struct socket *s, short flags);
  85.     long    (*setsockopt)    (struct socket *s, short level, short optname,
  86.                  char *optval, long optlen);
  87.  
  88.     long    (*getsockopt)    (struct socket *s, short level, short optname,
  89.                  char *optval, long *optlen);
  90. };
  91.  
  92. #ifndef NOEXTERNS
  93. /* create a new socket */
  94. extern struct socket     *so_create (void);
  95.  
  96. /* release socket to unconnecting state */
  97. extern long    so_release (struct socket *so);
  98.  
  99. /* register/unregister domains */
  100. extern void    so_register (short dom, struct dom_ops *ops);
  101. extern void    so_unregister (short dom);
  102.  
  103. /* add seleting proc's to the socket */
  104. extern long    so_rselect (struct socket *s, long proc);
  105. extern long    so_wselect (struct socket *s, long proc);
  106. extern long    so_xselect (struct socket *s, long proc);
  107.  
  108. /* wake selecting proc's */
  109. extern void    so_wakersel (struct socket *s);
  110. extern void    so_wakewsel (struct socket *s);
  111. extern void    so_wakexsel (struct socket *s);
  112.  
  113. /* make so1 and so2 a connected pair of sockets */
  114. extern void    so_sockpair (struct socket *so1, struct socket *so2);
  115.  
  116. /* Put `client' on the queue of incomplete connections of `server'.
  117.  * Blocks until the connection is accepted or it's impossible to
  118.  * establish the connection, unless nonblock != 0.
  119.  * `Backlog' is the number of pending connections allowed for `server'.
  120.  * so_connect() will fail if there are already `backlog' clients on the
  121.  * server queue.
  122.  */
  123. extern long    so_connect (struct socket *server, struct socket *client,
  124.                short backlog, short nonblock, short wakeup);
  125.  
  126. /* Take the first waiting client from `server's incomplete connection
  127.  * queue and connect `newsock' to it.
  128.  * Blocks until a connection request is available, unless nonblock != 0.
  129.  */
  130. extern long    so_accept (struct socket *server, struct socket *newsock,
  131.               short nonblock);
  132. #endif
  133.  
  134. #endif /* _NET_H */
  135.